package edu.nf.project.mappers.storeOperation.convention;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import edu.nf.project.entitys.dto.storeOperation.DishCargo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author gjh
 * @Date 2025/6/18
 * @Description: 菜品和货物的关联表
 */
@Mapper
public interface DishCargoMapper extends BaseMapper<DishCargo> {
    /**
     * 查询指定菜品所需的全部食材及其每份所需数量。
     * 一个菜品可能需要多个食材，比如一道“海鲜焗饭”需要虾仁、米饭、芝士等。
     * @param dishId 菜品ID
     * @return 该菜品所需的食材和用量列表
     */
    @Select("SELECT * FROM dish_cargo WHERE dish_id = #{dishId}")
    List<DishCargo> findByDishId(@Param("dishId") Integer dishId);


    @Select({
            "<script>",
            "SELECT * FROM dish_cargo",
            "WHERE dish_id IN",
            "<foreach collection='dishIds' item='id' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"
    })
    List<DishCargo> selectByDishIds(@Param("dishIds") List<Integer> dishIds);
}
